﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using FarseerPhysics;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;
using FarseerPhysics.Collision;
using FarseerPhysics.Factories;
using EpicBall.ScreenSystem;
using System.Collections.Generic;


namespace EpicBall.Levels.Classes
{
    public class Key : Collectable
    {
        protected int key_value;
        protected List<LevelObject> doors;

        //public Key(PhysicsGameScreen screen): this(screen, 1) { }
        public Key(PhysicsGameScreen screen, List<LevelObject> doorList): this(screen, doorList, 1) {}
        public Key(PhysicsGameScreen screen, List<LevelObject> doorList, int kvalue)
            : base(screen, screen.GameStack.Content.Load<Texture2D>("ObstacleTextures/key"))
        {
            key_value = kvalue;
            ScoreIncrement = 3;
            doors = doorList;
        }



        public override bool OnCollision(Fixture f1, Fixture f2, Contact contact)
        {
            _screen.Score += ScoreIncrement;
            _active = false;

            foreach (Door d in doors)
            {
                if (d.LockValue == this.key_value)
                {
                    d.Locked = false;
                }
            }

            _active = false;
            return false;
        }

        public override string type()
        {
            return "key";
        }
    }
}
